﻿using System;
using System.Text;
using System.Drawing;
using System.Buffers;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;

public static partial class glDRIVE
{
    /*
    函数 gl.gauss
    gauss消去法
    参数 a: a[n][n]系数矩阵。返回时被破坏。
    参数 b: b[n]常数向量，返回解向量。若系数矩阵奇异，则返回0向量。
    参数 n: 
    返回值 若系数矩阵奇异，则程序显示错误信息，并返回0标志值。否则返回非0标志值。
    */

    public static string drive_gauss()
    {
        int i, j;
        double[] x = new double[4];
        double[,] p = new double[4, 4];
        double[,] a = new double[4, 4]  {
            {0.2368,0.2471,0.2568,1.2671},
            {0.1968,0.2071,1.2168,0.2271},
            {0.1581,1.1675,0.1768,0.1871},
            {1.1161,0.1254,0.1397,0.1490}
        };
        double[] b = new double[4] {
            1.8471, 1.7471, 1.6471, 1.5471
        };
        for (i = 0; i < 4; i++)
        {
            for (j = 0; j < 4; j++) p[i, j] = a[i, j];
            x[i] = b[i];
        }

        string rs = "";
        rs += gl.html_table("Mat A:", a);
        rs += gl.html_table("Mat B:", b);

        i = gl.gauss(p, x, 4);
        if (i == 0) return "error: 0";
        rs += gl.html_table("Mat X:", x);
        return rs;
    }
}